package guoanmaker.operator.business.repository;

import java.util.Collection;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import guoanmaker.operator.business.model.ProvideCommodity;



public interface ProvideCommodityRepository  extends  JpaRepository<ProvideCommodity, String>, JpaSpecificationExecutor<ProvideCommodity>{

	
	
	@Query("select count(*) from ProvideCommodity p left join  p.providerBusiness pb where p.commodityState=2 and pb.id=:id ")
	public int findbyId(@Param("id") String id);
	@Query("select p from ProvideCommodity p left join  p.providerBusiness pb where p.commodityState=2 and pb.id=:id ")
	public List<ProvideCommodity> findbyCommditys(@Param("id") String id);
	@Query("select p from ProvideCommodity p where p.commodityState=2")
	public List<ProvideCommodity> findallCommditys();
	@Query("select p from ProvideCommodity p left join  p.providerBusiness pb where p.commodityState=8 and pb.id=:id ")
	public List<ProvideCommodity> findbyCommditystatue8(@Param("id") String id);
	
	@Query("select com from ProvideCommodity com  left join  com.providerBusiness pb where pb.id=:id and com.commodityState=2")
	public List<ProvideCommodity>  selectByCommodity(@Param("id") String id);
	
	@Query("select com from ProvideCommodity com  left join  com.providerBusiness pb where pb.personalUser.id=:id")
	public List<ProvideCommodity>  selectByCommodityUser(@Param("id") String id);
	/**
	 * 上架商品数量（在每个一级服务的包含范围）
	* @Title: findByserviceType_IdInAndCommodityStateIs 
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	* @param serviceTypeIds
	* @param stste
	* @return    设定文件 
	* @return List<ProvideCommodity>    返回类型 
	* @throws 
	 */
	public List<ProvideCommodity> findByserviceType_IdInAndCommodityStateIs(Collection<String> serviceTypeIds,Integer stste);
	public List<ProvideCommodity> findByserviceType_IdIn(Collection<String> serviceTypeIds);
	
	@Query("select com from ProvideCommodity com  where com.commodityCode=:commodityCode  and com.commodityState=2 and com.type!=1 and com.type!=4")
	public ProvideCommodity  selectByCommodityBypraThree(@Param("commodityCode") Integer commodityCode);
	
	@Query("select com from ProvideCommodity com  where com.serviceType.id=:serverid")
	public List<ProvideCommodity>  selectByCommodityByserverId(@Param("serverid") String serverid);
	@Query("select com from ProvideCommodity com  where com.serviceType.id=:serverid and com.commodityState!=6")
	public List<ProvideCommodity>  selectByCommodityByserverIdAndstate(@Param("serverid") String serverid);
	
	@Query("select com from ProvideCommodity com  where com.serviceType.id=:serverid and com.commodityState=2")
	public List<ProvideCommodity>  selectByserverIdAndstate(@Param("serverid") String serverid);
	
	@Query("select com from ProvideCommodity com  where com.commodityState !=6 and com.measurementUnit.id =:perviderDictionaryId")
	public List<ProvideCommodity> selectByCommodityStateAndPerviderDictionaryId(@Param("perviderDictionaryId")String perviderDictionaryId);
	
	@Query("select com from ProvideCommodity com  where com.commodityCode=:commodityCode and com.commodityState=2")
	public ProvideCommodity  selectByCommodityForCode(@Param("commodityCode") Integer commodityCode);
	
	@Query("select com from ProvideCommodity com  where com.commodityCode=:commodityCode and com.commodityState=2 and com.type!=4")
	public ProvideCommodity  selectByCommodityForCodebq(@Param("commodityCode") Integer commodityCode);
	
	
	
}
